package com.cenntro.common.util;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class MessageUtil {

	/** 未知错误 */
	public static Integer ERROR = -1;
	/** 参数错误 */
	public static Integer PARAM_ILLEGAL = -2;
	/** 无相关信息 */
	public static Integer NO_SUCH_INFOMATION = -3;
	/** 操作失败 */
	public static Integer OPERATE_FAILED = -4;
	/** 需要登录 */
	public static Integer NEED_TO_LOGIN = -8;

	private static MessageSource messageSource;
	static {
		messageSource = (MessageSource) ApplicationContextUtil.getApplicationContext().getBean("messageSource");
	}

	public static String getMsg(String key, Object... arg) {
		try{
			return messageSource.getMessage(key, arg, LocaleContextHolder.getLocale());
		}catch(Exception e){
			log.error("messageSource 国际化异常  key= {} ,arg ={}", key, arg, e);	
		}
		return  key;
	}
}
